<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*,util.*,dal.*,model.*,bll.*"%>
<%
String sql="";
int companyNum=0;
int employeeNum=0;
int productNum=0;
int unitNum=0;
int serviceNum=0;
int project_typeNum=0;
int task_typeNum=0;
int eventNum=0;
try
{
	
	Connection conn = ConnectionProvider.genConnection(); 
    Statement st;
    ResultSet rs;
    Class.forName("org.postgresql.Driver");    
    //conn=DriverManager.getConnection("jdbc:postgresql://localhost/buzzcomn","postgres","root");
    st = conn.createStatement();
    
    sql="select sp_company_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	companyNum=rs.getInt("sp_company_count");
    }
    
    sql="select sp_employee_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	employeeNum=rs.getInt("sp_employee_count");
    }
    
    sql="select sp_product_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	productNum=rs.getInt("sp_product_count");
    }
    
    sql="select sp_unit_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	unitNum=rs.getInt("sp_unit_count");
    }
    
    sql="select sp_service_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	serviceNum=rs.getInt("sp_service_count");
    }
    
    sql="select sp_project_type_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	project_typeNum=rs.getInt("sp_project_type_count");
    }
    
    sql="select sp_task_type_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	task_typeNum=rs.getInt("sp_task_type_count");
    }
    
    sql="select sp_event_count()";
    rs = st.executeQuery(sql);
    if(rs.next())
    {
    	eventNum=rs.getInt("sp_event_count");
    }
    
    
    
    st.close();
    conn.close();
    
       
}
catch(Exception e){}

String[] companyShortName=new String[companyNum];
String[] employeeName=new String[employeeNum];
String[] productShortName=new String[productNum];
String[] unitName=new String[unitNum];
String[] serviceName=new String[serviceNum];
String[] project_typeName=new String[project_typeNum];
String[] task_typeName=new String[task_typeNum];
String[] eventName=new String[eventNum];
try
{
	
	Connection conn = ConnectionProvider.genConnection(); 
    Statement st;
    ResultSet rs;
    Class.forName("org.postgresql.Driver");    
    //conn=DriverManager.getConnection("jdbc:postgresql://localhost/buzzcomn","postgres","root");
    st = conn.createStatement();
    sql="select * from company";
    rs=st.executeQuery(sql);
    int Index=0;
    while(rs.next())
    {
    	companyShortName[Index]=rs.getString("short_name");
    	Index++;
    }
    
    sql="select * from employee";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	employeeName[Index]=rs.getString("name");
    	Index++;
    }
    
    sql="select * from product";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	productShortName[Index]=rs.getString("short_name");
    	Index++;
    }
    
    sql="select * from unit";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	unitName[Index]=rs.getString("name");
    	Index++;
    }
    
    sql="select * from service";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	serviceName[Index]=rs.getString("name");
    	Index++;
    }
    
    sql="select * from project_type";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	project_typeName[Index]=rs.getString("name");
    	Index++;
    }
    
    sql="select * from task_type";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	task_typeName[Index]=rs.getString("name");
    	Index++;
    }
    
    sql="select * from event";
    rs=st.executeQuery(sql);
    Index=0;
    while(rs.next())
    {
    	eventName[Index]=rs.getString("name");
    	Index++;
    }
    
    
    st.close();
    conn.close();
    
       
}
catch(Exception e){}
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Insert title here</title>
	<link href="css/hyjack.css" rel="stylesheet" type="text/css" />
	<script src="js/jquery-1.4.4.min.js" type="text/javascript" language="javascript"></script>
    <script src="js/jquery.hyjack.select.js" type="text/javascript" language="javascript"></script>
    <script src="js/jquery.hyjack.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajax.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddCompany.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddEmployee.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddProduct.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddUnit.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddService.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddProject_type.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddTask_type.js" type="text/javascript" language="javascript"></script>
    <script src="js/ajaxAddEvent.js" type="text/javascript" language="javascript"></script>
    
    <script type="text/javascript">
	    
		////////////////////////////////////////////////
		// Perform adding 5 items and update
		////////////////////////////////////////////////
		function addItems(selector){
			if(!selector) return;
			var answer = prompt ("please input new name","");
			$(selector).append( 
					$('<option/>').val(answer).html(answer) 
				); 
			$.hyjack_select.update(selector);
			if(selector=='#company')
			{
				addCompany(answer);
			}
			if(selector=='#employee')
			{
				addEmployee(answer);
			}
			if(selector=='#product')
			{
				addProduct(answer);
			}
			if(selector=='#unit')
			{
				addUnit(answer);
			}
			if(selector=='#service')
			{
				addService(answer);
			}
			if(selector=='#project_type')
			{
				addProject_type(answer);
			}
			if(selector=='#task_type')
			{
				addTask_type(answer);
			}
			if(selector=='#event')
			{
				addEvent(answer);
			}
			
		}

	</script>
</head>
<body>
	<table>
	<tr>
	<th>COMPANY</th>
	<td>
	<select id="company" class="hyjack">
	<%
		for(int i=0;i<companyNum;i++)
		{
	%>
			<option value="<%=companyShortName[i]%>"><%=companyShortName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#company');">  
	</td>  
	</tr>
	<tr>
	<th>EMPLOYEE</th>
	<td>
	<select id="employee" class="hyjack">
	<%
		for(int i=0;i<employeeNum;i++)
		{
	%>
			<option value="<%=employeeName[i]%>"><%=employeeName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#employee');">  
	</td>  
	</tr>
	<tr>
	<th>PRODUCT</th>
	<td>
	<select id="product" class="hyjack">
	<%
		for(int i=0;i<productNum;i++)
		{
	%>
			<option value="<%=productShortName[i]%>"><%=productShortName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#product');">  
	</td>
	</tr>
	<tr>
	<th>UNIT</th>
	<td>
	<select id="unit" class="hyjack">
	<%
		for(int i=0;i<unitNum;i++)
		{
	%>
			<option value="<%=unitName[i]%>"><%=unitName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#unit');">  
	</td>
	</tr>
	<tr>
	<th>SERVICE</th>
	<td>
	<select id="service" class="hyjack">
	<%
		for(int i=0;i<serviceNum;i++)
		{
	%>
			<option value="<%=serviceName[i]%>"><%=serviceName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#service');">  
	</td>
	</tr>
	<tr>
	<th>PROJECT_TYPE</th>
	<td>
	<select id="project_type" class="hyjack">
	<%
		for(int i=0;i<project_typeNum;i++)
		{
	%>
			<option value="<%=project_typeName[i]%>"><%=project_typeName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#project_type');">  
	</td>
	</tr>
	<tr>
	<th>TASK_TYPE</th>
	<td>
	<select id="task_type" class="hyjack">
	<%
		for(int i=0;i<task_typeNum;i++)
		{
	%>
			<option value="<%=task_typeName[i]%>"><%=task_typeName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#task_type');">  
	</td>
	</tr>
	<tr>
	<th>EVENT</th>
	<td>
	<select id="event" class="hyjack">
	<%
		for(int i=0;i<eventNum;i++)
		{
	%>
			<option value="<%=eventName[i]%>"><%=eventName[i]%></option>
			
	<%
		}
	%>
			
			
		</select> 
		</td>
		<td>
		<input type="button" value="Add" onclick="addItems('#event');">  
	</td>
	</tr>
	
	<tr>
	<td></td>
	<td>
		<div class="buttons">
			<select id="width" >
				<option value="100px">Default</option>
				<option value="200px">200px</option>
				<option value="400px">400px</option>
			</select> 
			
		</div>
	</td>
	<td><input type="button" onclick="changeWidthAll()" value="Change Width" /></td>
		</table>
</body>
</html>